<!DOCTYPE html>
<head>
<title>Campeonato de Futbol</title>
</head>

<style type="text/css"> 
body{ 
    background-image: url(fondo.jpg); 
    background-size: cover;
    -moz-background-size: cover;
    -webkit-background-size: cover;
    -o-background-size: cover;
    background-position : center; 
    background-repeat : no-repeat; 
    background-attachment : fixed; 
} 
</style> 
<body>
<option id="hm" value="home.php"></option>
<input type="button" onclick="document.location.href=document.getElementById('hm').value" value="Home">
</body>
<center>
<h1>Listado de goleadores</h1>
</center>

<?php

$db = pg_connect("host=localhost dbname=boti user=no-jodas password=1234");

$query = "SELECT nombre_del_empleado, COUNT(*) AS cantidad_de_goles FROM empleados 
JOIN estadistica
ON empleados.dni_del_empleado=estadistica.dni_del_empleado
WHERE estadistica.tipo_de_la_estadistica = 'gol_favor' GROUP BY empleados.nombre_del_empleado
ORDER BY cantidad_de_goles DESC";

$result = pg_query($query);
$rows = pg_numrows($result);

echo '<center>';
echo '<table bgcolor=#A9E2F3 width = 300 border = 1>';
echo "\t\t<td><h2><center>Jugador</center></h2></td>\n";
echo "\t\t<td><h2><center>Goles</center></h2></td>\n";

for($i=1; $i<=$rows; $i++){
    
    $line = pg_fetch_array($result, null, PGSQL_ASSOC);
    echo '<tr>';
    echo "\t\t<td><h3><center>$line[nombre_del_empleado]</center></h3></td>\n";
    echo "\t\t<td><h3><center>$line[cantidad_de_goles]</center></h3></td>\n";
    echo '</tr>';

}
echo '</table>';
echo '</center>';

?>

